#ifndef _CCQBuff
#define _CCQBuff

#define DEFCCQB_DEFAULT_BUFF_SIZE 1024	//default buffer size 

#ifndef BYTE
#define BYTE unsigned char
#endif

#include <stdlib.h>
#include <string>

using namespace std ;

class CCircleQueueBuff	// circle queue buffer class
{
protected:
	BYTE *m_pBuff;	//Queue buffer point
	int m_nMaxBuffSize;	//max buffer size
	int m_nHead;	//Data start position
    int m_nDataSize;	//Storing date size.
public:
	CCircleQueueBuff(int nMaxSize = DEFCCQB_DEFAULT_BUFF_SIZE);
	~CCircleQueueBuff();
	
	bool Clean(BYTE nFillByte = 0x00);	//Clean up the buffer with FillByte.
	int getAvailableDataLenght(); //Get now date length.
	int getEmptySpaceLenght();	//Get now empty space lenght.
	//write to buffer
	int WriteData(BYTE *pData, int nLen);	//Write data to CCQBuff. Return written size.
	int WriteDataMakeAllSure(BYTE *pData, int nLen);	//Write data to CCQBuff and promise all data will be store. Otherwise, return 0 and nothing will be store.
	//read from buffer
	int ReadData(BYTE *pBuf, int nMaxLen); //Read data from CCQBuff. Store the data to pBuf.
	int ReadDataMakeAllSure(BYTE *pBuf, int nMaxLen);	//Read data from CCQBuff and promise all data will be read. Otherwise, return 0 and nothing will be Read.
	string GetString(char endSymbol = '\0');	//Get string from buffer with endSymbol.
};

#endif	//#ifndef _CCQBuff